-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a command to install a git hook to automatically run x.py test tidy --bless
#76356
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
r? @jyn514 hello! tagging you because you responded to my thread on zulip. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me on the idea, but r? @Mark-Simulacrum for the implementation
More discussion about this in https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/git.20hooks. |
Hi @caass, this is waiting on you to address some review comments. Let me know if you're having trouble and I'm happy to help! |
You could add Line 424 in 9e5f7d5
Other than that I saw you already opened rust-lang/rustc-dev-guide#848 so no need to document it further I think. It would be nice to test that x.py run -h -v shows install-git-hook though.
|
This probably doesn't need introduction of a new compiled tool. |
Hmm, that doesn't seem very discoverable - not many people look at That said I do like having it in |
Actually, this is the first time I hear about |
Adding the script to |
This comment has been minimized.
This comment has been minimized.
What's the status of this? |
This is waiting on the author to address review comments. |
yes i accidentally broke my fork of rust somehow so it's been slow going :( soon i'll probably just |
It's ok, now I'm writing enough Rust that i'm able to get my fix elsewhere
Ok! Based on the discussion above, I removed the integration with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like the right approach :) A few nits but mostly looks good.
Are you interested in adding some logic to set this up in x.py setup
? That seems like a good place for this to go and wouldn't require reading the dev guide. I would expect it to prompt the user before installing a git hook:
$ x.py setup
... all the current output ...
Set up a git hook that runs `x.py tidy` [y]/n? y
Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`
Ideally it would use a hard link so the script doesn't get out of date.
No problem if not, this is fine to leave for a follow-up PR.
src/etc/pre-commit.sh
Outdated
# For help running bash scripts on Windows, | ||
# see https://stackoverflow.com/a/6413405/6894799 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe a good follow-up would be to have a version of this for powershell too. No need to add it now though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can tell, git only understands unix-like scripts, and won't run e.g. pre-commit.ps1
. I suspect that if the user has git installed, they'll be able to run git scripts as well, so actually this line is redundant...I think...I haven't used git on windows in a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @mati865 - do you know if this will work on windows, and if not, how to make it work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jyn514 Git for Windows ships bash shell.
I haven't tried using hooks there but they should work.
I hate powershell so personally I use bash/zsh everywhere, even on Windows.
|
||
Ok(if should_install { | ||
let src = src_path.join("src").join("etc").join("pre-commit.sh"); | ||
let dst = src_path.join(".git").join("hooks").join("pre-commit"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit: this plays badly with worktrees. Do you mind changing it to use git rev-parse --git-common-dir
instead?
x.py encountered an error -- do you already have the git hook installed?
Not a directory (os error 20)
Although I guess the user might not want to install it globally for all worktrees ... I'm not sure what the right behavior is here. Let's leave it for now and we can fix it in a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i also noticed a similar error trying to run a merge commit...i'm kind of starting to get out of my league at this point tho so i'm more than happy to move it to a follow up 😅
@bors r+ Thanks for working on this! I think windows and worktree support can go in a follow-up PR if necessary. |
📌 Commit 0845627 has been approved by |
⌛ Testing commit 0845627 with merge 962fe4442fb751b1b115aeb8042f9da65530219b... |
💥 Test timed out |
Timed out on x86_64 apple :( @bors retry FYI @rust-lang/infra
|
☀️ Test successful - checks-actions, checks-azure |
This is a companion to [this PR](rust-lang/rust#76356), which deals with including functionality for automatically running `tidy --bless` on each commit. Undo editor auto-formatting and clarify git hook renaming a word Phrasing Apply suggestions from code review Co-authored-by: Camelid <37223377+camelid@users.noreply.github.com>
Some folks (such as myself) would probably find a lot of convenience in a pre-commit hook that automatically runs tidy before committing, to avoid burning CI time learning that your commit wasn't tidy.
I'm absolutely positive I have missed some stuff. I basically just got this to where you can run
./x.py run install-git-hook
and then clicked the commit button. Please let me know what else you'd like me to add before this can be merged!rustc-dev-guide companion PR